Method for encoding information in communication network

ABSTRACT

Embodiments of the application provide a method for encoding data in a wireless communication network. A communication device obtains K data bits and a target code length M. The device determines a mother code length N 1 . The device encodes the K data bits to obtain an encoded bit sequence of code langth N 1 . The mother code length N 1  is determined according to a minimum value of values N a , N max  and N. The values N a , N max  and N satisfy the following conditions: (1) the value N a  satisfies with: a rate R 1  is less than or equal to a preset rate, wherein the rate R 1  is determined according to the value K and the value N a ; (2) the value N max  is a preset maximum mother code length, and N max  is an integer power of 2; and (3) the value N satisfies with M≤N*(1+δ), and δ is a preset constant.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of International Application No.PCT/CN 2018/070056, filed on Jan. 2, 2018, which claims priority toChinese Patent Application No. 201710157341.3, filed on Mar. 16, 2017and Chinese Patent Application No. 201710007883.2, filed on Jan. 5,2017. The disclosures of the aforementioned patent applications arehereby incorporated by reference in their entireties.

TECHNICAL FIELD

Embodiments of the application relate to the communications field, andmore specifically, to method and apparatus for encoding information.

BACKGROUND

Channel encoding is used in communication systems to improve datatransmission reliability, so as to ensure communication quality. Polarcodes, proposed by Professor Arikan of Turkey, are the first kind ofcodes that are theoretically proven to be able to achieve the

Shannon capacity and having low encoding and decoding complexity.

A polar code is a linear block code. An encoding matrix of the polarcode is G_(N), which is an N x N matrix.

An encoding process for generating a polar code x₁ ^(N)(x₁ ^(N)=x₁, x₂,. . . , x_(N)) is:

x₁ ^(N)=u₁ ^(N)G_(N)

where u₁ ^(N)=(u₁, u₂,K,u_(N)) is a binary row vector having a length ofN bits (N is also called a mother code length), G_(N) is the codingmatrix, and G_(N)=F₂ ^(⊗(log) ² ^((N))). F₂ ^(⊗(log) ² ^((N))) is aKronecker product of a number of log₂ N matrices F₂, and the matrix F₂is:

$F_{2} = {\begin{bmatrix}1 & 0 \\1 & 1\end{bmatrix}.}$

In the encoding process of the polar code, some bits in the row vectoru₁ ^(N) are used to carry information, and these bits are referred to asinformation bits. An index set of these bits is represented by a set A.Other bits are set to a fixed value that is pre-agreed upon between areceiving end and a transmitting end of the polar code, and these bitsare referred to as fixed bits or frozen bits. An index set of the fixedbits or frozen bits is represented by a set A^(c), which is a complementset of set A.

The encoding process of the polar code x₁ ^(N)=u₁ ^(N)G_(N) isequivalent to x₁ ^(N)=u_(A)G_(N)(A)⊗u_(A) _(c) G_(N)(A^(C)). Herein,G_(N)(A) is a submatrix formed by rows in the G_(N) that correspond toindexes in the set A, and G_(N)(A^(c)) is a submatrix formed by rows inthe G_(N) that correspond to indexes in the set A^(c). u_(A) is aninformation bit set of the U₁ ^(N), and the number of the informationbits in the u_(A) is K. u_(A) _(c) is a frozen bit set of the u₁ ^(N),and the number of the frozen bits in the u_(A) _(c) is N-K. The frozenbits are known bits. Value of the frozen bits is normally set to 0, butthe value of the frozen bits may be randomly set, provided that thereceiving end and the transmitting end of the polar code have pre-agreedon the value of the frozen bits. When the frozen bits are set to 0, apolar code encoding output may be simplified as x₁ ^(N)=u_(A)G_(N)(A),in which G_(N)(A) is a KxN matrix.

A process of constructing a polar code is a process of selecting the setA, and the selection of the set A determines the performance of thepolar code. The process of constructing the polar code normallyincludes: determining, based on a mother code length N, that a total ofN polarized channels exist, where each of the polarized channelscorresponds to one row in an encoding matrix, respectively; calculatinga reliability of each of the polarized channels; forming the informationbit index set A using indexes of first K polarized channels withrelatively high reliabilities, and forming the frozen bit index set A^(c) using indexes of the remaining (N-K) polarized channels. The set Adetermines bit positions of the information bits in x₁ ^(N), and the setA ^(c) determines bit positions of the frozen bits in x₁ ^(N).

It can be learned from the encoding matrix that a code length of anoriginal polar code (mother code) is an integer power of 2. In practicalapplications, however, length of a polar code need to be set to any codelength, and this is achieved by a process called rate matching.

In the prior art, a puncturing or a shortening manner is used for ratematching. A mother code whose length exceeds a target code length isusually punctured or shortened, to achieve the target code length. Thepunctured or shortened code is filled during decoding, to restore to thelength of the mother code. Buffer sizes, complexity, and delays duringthe encoding and the decoding are related to the mother code length.When a relatively large quantity of bits are shortened or punctured (forexample, the mother code is shortened or punctured from 2048 bits to1200 bits), additional overheads due to the puncturing are quite high.An increase in the target code length results in a decrease in a coderate. On the one hand, this may bring an encoding gain; on the otherhand, the complexity also increases as the mother code length increases.

SUMMARY

Embodiments of the present application provide a rate matching method,an encoding apparatus, a rate de-matching method, a decoding apparatus,and a communications apparatus, to reduce complexity of polar encodingand decoding.

According to a first aspect, a rate matching method for a polar code isprovided, including: obtaining an information bit sequence and a targetcode length M of a polar code; and when the target code length M meets apreset condition, using a polar code with a first mother code length N₁to encode the information bit sequence, to output a first encoded bitsequence, where N₁ is less than or equal to M, and N₁ is an integerpower of 2, and repeating at least some bits in the first encoded bitsequence, to obtain a first target polar code with a length M; or whenthe target code length M does not meet the preset condition, using apolar code with a second mother code length N₂ to encode the informationbit sequence, to output a second encoded bit sequence, where N₂ isgreater than or equal to M, and N₂ is an integer power of 2, andshortening or puncturing the second encoded bit sequence, to obtain asecond target polar code with a length M.

According to a second aspect, an encoding apparatus is provided,including:

an obtaining unit, configured to obtain an information bit sequence anda target code length M of a polar code;

an encoding unit, configured to: when the target code length M meets apreset condition, use a polar code with a first mother code length N₁ toencode the information bit sequence, to output a first encoded bitsequence, wherein N₁ is less than or equal to M, and N₁ is an integerpower of 2; or when the target code length M does not meet the presetcondition, use a polar code with a second mother code length N₂ toencode the information bit sequence, to output a second encoded bitsequence, where N₂ is greater than or equal to M, and N₂ is an integerpower of 2; and

a rate matching unit, configured to: repeat at least some bits in thefirst encoded bit sequence, to obtain a first target polar code with alength M; or shorten or puncture the second encoded bit sequence, toobtain a second target polar code with a length M.

According to a third aspect, a communications apparatus is provided,including:

a transceiver, configured to communicate with another device;

a memory, configured to store a program; and

a processor, configured to execute the program stored in the memory,when the program is executed, the processor is configured to: when atarget code length M during polar encoding meets a preset condition, usea polar code with a first mother code length N₁ to encode an informationbit sequence, to output a first encoded bit sequence, where N₁ is lessthan or equal to M, and N₁ is an integer power of 2, and repeat at leastsome bits in the first encoded bit sequence, to obtain a first targetpolar code with a length M; or when the target code length M does notmeet the preset condition, use a polar code with a second mother codelength N₂ to encode the information bit sequence, to output a secondencoded bit sequence, where N₂ is greater than or equal to M, and N₂ isan integer power of 2, and shorten or puncture the second encoded bitsequence, to obtain a second target polar code with a length M.

According to a fourth aspect, a rate de-matching method for a polar codeis provided, including:

receiving a log-likelihood ratio LLR of a to-be-decoded bit sequencewith a length M, where M is a target code length during polar encoding;and

when the target code length M meets a preset condition, determining thata transmitting end uses a repetition manner; determining a location of arepeated bit; adding and combining an LLR, at a repetition location, inreceived LLRs of M bits, to obtain an LLR of a first to-be-decoded bitsequence whose length is a first mother code length N₁, where N₁ is lessthan or equal to M, and N₁ is an integer power of 2; and polar decodingbased on the LLR of the first to-be-decoded bit sequence; or

when the target code length M does not meet the preset condition,determining that the transmitting end uses a shortening or puncturing;determining a shortening or puncturing location and an LLR at theshortening or puncturing location; restoring the received LLRs of M bitsto a second mother code length N₂, to obtain an LLR of a secondto-be-decoded bit sequence whose length is the second mother code lengthN₂, where N₂ is greater than or equal to M, and N₂ is an integer powerof 2; and polar decoding based on the LLR of the second to-be-decodedbit sequence.

According to a fifth aspect, a decoding apparatus is provided,including:

a receiving unit, configured to receive a log-likelihood ratio LLR of ato-be-decoded bit sequence with a length M, wherein M is a target codelength during polar encoding;

a rate de-matching unit, configured to: when the target code length Mmeets a preset condition, determine that a transmitting end uses arepetition manner to implement rate matching; determine a location of arepeated bit; and add and combine an LLR, at a repetition location, inreceived LLRs of M bits, to obtain an LLR of a first to-be-decoded bitsequence whose length is a first mother code length N₁, where N₁ is lessthan or equal to M, and N₁ is an integer power of 2; or configured to:when the target code length M does not meet the preset condition,determine that the transmitting end uses a shortening or puncturingmethod to implement rate matching; determine a shortening or puncturinglocation and an LLR at the shortening or puncturing location; andrestore the received LLRs of M bits to a second mother code length N₂,to obtain an LLR of a second to-be-decoded bit sequence whose length isthe second mother code length N₂, where N₂ is greater than or equal toM, and N_(b 2) is an integer power of 2; and

a decoding unit, configured to perform polar decoding based on the LLRof the first to-be-decoded bit sequence or the LLR of the secondto-be-decoded bit sequence.

According to a sixth aspect, a communications apparatus is provided,including:

a transceiver, configured to communicate with another device;

a memory, configured to store a program; and

a processor, configured to execute the program stored in the memory,where when the program is executed, the processor is configured to: whena target code length M during polar encoding meets a preset condition,determine that a transmitting end uses a repetition manner to implementrate matching; determine a location of a repeated bit; add and combinean LLR, at a repetition location, in received LLRs of M bits, to obtainan LLR of a first to-be-decoded bit sequence whose length is a firstmother code length N₁, where N₁ is less than or equal to M, and N₁ is aninteger power of 2; and perform polar decoding based on the LLR of thefirst to-be-decoded bit sequence; or

when the target code length M does not meet the preset condition,determine that the transmitting end uses a shortening or puncturingmethod to implement rate matching; determine a shortening or puncturinglocation and an LLR at the shortening or puncturing location; restorethe received LLRs of M bits to a second mother code length N₂, to obtainan LLR of a second to-be-decoded bit sequence whose length is the secondmother code length N₂, where N₂ is greater than or equal to M, and N₂ isan integer power of 2; and perform polar decoding based on the LLR ofthe second to-be-decoded bit sequence.

According to a seventh aspect, a rate matching method for a polar codeis provided, including:

obtaining an information bit sequence and a first code rate R₁, whereR₁=K/N₁, K is a quantity of the information bits, N₁=2^(n), n is aninteger less than or equal to log₂ M, and M is a target code lengthduring polar encoding;

if the first code rate R₁ is less than or equal to a predeterminedsecond code rate R₂, using a polar code with a mother code length N₁ toencode the information bit sequence, to output N₁ encoded bits; andrepeating at least some of the N₁ encoded bits, to obtain a first targetpolar code with a length M; or

if the first code rate R₁ is greater than the second code rate R₂, usinga polar code with a mother code length N₂ to encode the information bitsequence, to output N₂ encoded bits, where N₂ is greater than or equalto the target code length M, and N₂ is an integer power of 2; andshortening or puncturing the N₂ encoded bits, to obtain a second targetpolar code with a length M.

According to an eighth aspect, a rate matching method for a polar codeis provided, and the method includes:

obtaining a preset maximum mother code length N_(max), where N_(max) isan integer power of 2; and

if a target code length M during polar encoding is greater than themaximum mother code length N_(max), using a polar code with a mothercode length N_(max) to encode an information bit sequence, to outputN_(max) encoded bits; and repeating at least some of the N_(max) encodedbits, to obtain a first target polar code with a length M; or

if the target code length is less than the maximum mother code lengthN_(max), using a polar code with a mother code length N to encode theinformation bit sequence, to output N encoded bits, where N is greaterthan or equal to the target code length M, and N is an integer power of2; and shortening or puncturing the N encoded bits, to obtain a secondtarget polar code with a length M.

According to a ninth aspect, a rate matching method for a polar code isprovided, and the method includes:

obtaining an information bit sequence and a target code length M of apolar code; and

selecting, from a set of values of a first mother code length Ni thatmeet any one of the following three preset conditions, a minimum valueas a value of the first mother code length N₁, and using a repetitionrate matching scheme; or if no value of the first mother code length N₁meets any one of the following preset conditions, using a shortening orpuncturing rate matching scheme, where the three preset conditions are:

a first code rate R₁ determined based on a quantity K of the informationbits and the target code length M is less than or equal to a presetsecond code rate R₂, and R₁=K/N₁;

the target code length is greater than a preset maximum mother codelength N_(max), and the first mother code length N₁ is N_(max); and

a difference between the target code length M and the first mother codelength N₁ is less than a preset range, wherein N₁ is less than or equalto M, and N₁ is an integer power of 2.

With reference to the first aspect, the second aspect, the third aspect,the seventh aspect, or the eighth aspect, in a possible implementation,the at least some bits in the first encoded bit sequence are repeatedaccording to a preset rule, and the preset rule includes any one of thefollowing manners: in an order from back to front, in an order fromfront to back, in a random order, in a bit reversal order from back tofront, in a bit reversal order from front to back, or in a descendingorder of reliability.

With reference to the fourth aspect, the fifth aspect, or the sixthaspect, in a possible implementation, the repetition location isdetermined according to a preset rule, and the preset rule includes anyone of the following manners: in an order from back to front, in anorder from front to back, in a random order, in a bit reversal orderfrom back to front, in a bit reversal order from front to back, or in adescending order of reliability.

With reference to any one of the first aspect to the sixth aspect, in apossible implementation, the preset condition is: a first code rate R₁determined based on a quantity K of the information bits and the targetcode length is less than or equal to a preset second code rate R₂, wherethe first code rate is R₁=K/N₁, K is a quantity of to-be-encodedinformation bits, N₁=2^(n), and n is an integer less than or equal tolog₂ M. In a possible implementation, the first mother code length is amaximum integer less than or equal to log2 M. In a possibleimplementation, a value of the second code rate is 1/4, 1/3, 1/4, 1/5,1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 2/7, 3/8, 2/9, 3/10, 2/11, or3/11.

With reference to any one of the first aspect to the sixth aspect, in apossible implementation, the preset condition is: the target code lengthis greater than a preset maximum mother code length N_(max). In apossible implementation, the first mother code length is N_(max). In apossible implementation, N_(max) is 8192, 4096, 2048, 1024, 512, 256,128, or 64.

With reference to all of the foregoing aspects, in a possibleimplementation, the second mother code length is a minimum integer powerof 2 that is greater than or equal to the target code length.

With reference to any one of the first aspect to the sixth aspect, in apossible implementation, the preset condition is: at least one of thefollowing conditions is met, and a minimum value in a set of alldetermined values of the first mother code length that meet any one ofthe following conditions is used as a value of the first mother codelength:

a first code rate R₁ determined based on a quantity K of the informationbits and the target code length M is less than or equal to a presetsecond code rate R₂, and R₁=K/N₁;

the target code length is greater than a preset maximum mother codelength N_(max), and N₁=N_(max); or

a difference between the target code length M and the first mother codelength N₁ is less than a preset range.

With reference to any one of the first aspect to the sixth aspect, in apossible implementation, the preset condition is: a difference betweenthe target code length M and the first mother code length N₁ is lessthan a preset range, where N₁ is less than or equal to M, and N₁ is aninteger power of 2. In a possible implementation, that a differencebetween the target code length M and the first mother code length N₁ isless than a preset range is indicated by one of the following:

M ≤ N₁ * (1 + δ); ${\frac{M}{N_{1}} \leq \left( {1 + \delta} \right)};$M − N₁ ≤ N₁ * δ; or $\frac{M - N_{1}}{N_{1}} \leq {\delta.}$

In a possible implementation, δ is a constant, for example, a value maybe 1/8, 1/4, or 3/8.

In a possible implementation, a value of δ is a function of a first coderate R₁, δ decreases as R₁ increases, and

$R_{1} = {\frac{K}{N_{1}}.}$

In a possible implementation, a function relationship between δ and thefirst code rate R₁ is:

δ=β*(1−R₁), or δ=β*(1−R₁)², where β is a constant, for example, β may be1/2, 3/8, 1/4, 1/8, or 1/16.

In a possible implementation, a function relationship between δ and thefirst code rate R₁ is:

$\delta = \left\{ {\begin{matrix}{a,} & {{{if}\mspace{14mu} R_{1}} < R_{3}} \\{0,} & {{{if}\mspace{14mu} R_{1}} \geq R_{3}}\end{matrix},} \right.$

where

a is a constant and may be 1/16, 1/4, 3/8, 1/2, or the like, R₃ is acode rate threshold and is a constant, and R₃ may be 1/4, 1/6, 1/3, 1/5,1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 2/7, 3/8, 2/9, 3/10, 2/11, 3/11, or thelike.

Another aspect of this application provides a computer readable storagemedium, the computer readable storage medium stores an instruction, andwhen the instruction is run on a computer, the computer executes themethod described in the foregoing aspects.

Another aspect of this application provides a computer program productincluding an instruction, and when the computer program product is runon a computer, the computer executes the method described in theforegoing aspects.

Another aspect of this application provides a computer program, and whenthe computer program is run on a computer, the computer executes themethod described in the foregoing aspects.

Another aspect of this application provides a communications apparatus,including:

a memory, configured to store a program; and

a processor, configured to execute the program stored in the memory,where when the program is executed, the processor is configured toexecute the method described in the first aspect, the fourth aspect, theseventh aspect, the eighth aspect, or the ninth aspect, or execute anypossible implementation of the first aspect, the fourth aspect, theeighth aspect, or the ninth aspect.

In the embodiments of this application, which rate matching manner is tobe used is determined based on the target code length. When the presetcondition is met, the repetition is used. Because the mother code lengthis less than or equal to the target code length, when the target codelength is not an integer power of 2, the used mother code length is lessthan a mother code length determined in a shortening or puncturing. Thiscan meet an encoding gain requirement and reduce encoding and decodingcomplexity, thereby reducing a delay. When the target code length doesnot meet the preset condition, the shortening or puncturing is used. Adecoder side determines, in a corresponding manner, a rate matchingmanner used by an encoder side, and performs rate de-matching anddecoding. According to the embodiments of this application, a desirablebalance is achieved between an encoding gain loss and complexity.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a schematic diagram of a basic wireless communication processbetween a transmitting end and a receiving end;

FIG. 2 is a block diagram of an encoding apparatus according to anembodiment of this application;

FIG. 3 is a flowchart of a rate matching method according to anembodiment of this application;

FIG. 4 is a schematic diagram of a cyclic buffer according to anembodiment of this application;

FIG. 5 is a diagram of a performance comparison in an additive whitegaussian noise (AWGN) channel between a repetition-based rate matchingmanner and a shortening-based rate matching manner that are determinedby using a code rate threshold;

FIG. 6 is a diagram of a performance comparison in an AWGN between arepetition-based rate matching manner and a shortening-based ratematching manner that are determined by using a maximum mother codelength;

FIG. 7 is a schematic diagram of a communications apparatus according toan embodiment of this application;

FIG. 8 is a schematic diagram of a decoding apparatus according to anembodiment of this application;

FIG. 9 is a flowchart of a rate de-matching method according to anembodiment of this application; and

FIG. 10 shows a performance comparison between a repetition-based mannerand a puncturing-based manner when M=160 and K has different values.

DESCRIPTION OF EMBODIMENTS

FIG. 1 shows a basic procedure of wireless communication. Communicationsignals are transmitted from a transmitting device (referred to astransmitting end hereinafter) to a receiving device (referred asreceiving end hereinafter). At the transmitting end, a signal from asignal source is source encoded, channel encoded, rate matched,modulation mapped, and then transmitted to the receiving end. At thereceiving end, after de-mapping demodulation, rate de-matching, channeldecoding, and source decoding, the signal is output to a signaldestination. In channel encoding and channel decoding, the polar codingprocess as described above can be used. Because a code length of anoriginal polar code (mother code) is an integer power of 2, in practicalapplications, the code length may need to be adjusted to a differentcode length. This can be achieved through rate matching. As shown inFIG. 1, at the transmitting end, the rate matching is performed afterthe channel encoding, to achieve any target code length. At thereceiving end, a rate de-matching is performed before channel decoding,to restore the polar code to its original length.

The technical solutions in the embodiments of this application may beapplied to the fifth generation (5G) communication systems, and may alsobe applied to other communications systems, such as Global System forMobile Communications (GSM), Code Division Multiple Access (CDMA)systems, Wideband Code Division Multiple Access (WCDMA) systems, GeneralPacket Radio Service (GPRS) systems, Long Term Evolution (LTE) systems,LTE Frequency Division Duplex (FDD) systems, LTE Time Division Duplex(TDD) systems, and Universal Mobile Telecommunication Systems (UMTS).

According to a rate matching method for a polar code provided in anembodiment of this application, a mother code length, that is less thanor equal to a target code length (and greater than a quantity ofinformation bits) and that is an integer power of 2, is determined. Apolar code is constructed and encoded based on the determined mothercode length. The encoded bits are repeated, to obtain a target codelength, so as to implement rate matching on the polar code. A ratematching and rate de-matching process is as follows:

(1) Determine a mother code length N=2^(n) that is less than or equal toa target code length M and that is an integer power of 2 (n≤log₂ M, andn is an integer). The target code length M is determined based on aquantity K of information bits and a code rate R, and M=INT(K/R), whereINT indicates rounding.

(2) Construct a polar code whose mother code length is N and whosequantity of information bits is K, and encode the polar code, to obtainan encoded bit sequence.

(3) Repeat at least some bits in the encoded bit sequence according to apreset order, until the target code length M is reached, to obtain arate matched bit sequence.

(4) A receiving end obtains log-likelihood ratios (LLRs) of the M bits,determines locations of repeated bits, and combines LLRs of repeatedlocations, to obtain LLRs of N to-be-decoded bits, so as ratede-matching the received M bits. The receiving end then performsdecoding based on the LLRs of the N to-be-decoded bits.

In the repetition manner of rate matching, because the mother codelength is less than the target code length, and the mother code lengthis less than that in solutions used in the prior art, encoding anddecoding complexity is reduced.

When a mother code length is larger, performance caused by an encodinggain is better, but complexity is higher. A decrease in a code rateresults in an increase in a mother code length, and less performanceimprovement is achieved by the encoding gain. Therefore, a problem ofbalancing an encoding gain and complexity may be further resolved byusing an encoding parameter. For example, a condition may be set for atarget code length. When the condition is met, a repetition manner isused to implement rate matching. In the repetition manner, a mother codelength is less than the target code length. In this case, complexity isrelatively low, and a gain loss caused by the repetition falls within anacceptable range. When the specified condition is not met, a puncturingor shortening manner is used to implement rate matching. In this case, adetermined mother code length is greater than the target code length,and the target code length is obtained through shortening or puncturing.In this case, complexity is relatively high, but a gain loss is reduced.

An encoding apparatus 200 is shown in FIG. 2. The encoding appatatus 200includes an obtaining unit 201, an encoding unit 202 and a rate matchingunit 203. The encoding appatatus 200 is configured to perform encodingand rate matching. As shown in FIG. 3, an encoding and rate matchingprocess includes the following oprerations.

301. Obtain an information bit sequence, and obtain a target code lengthM of a polar code.

This step may be implemented by the obtaining unit 201 in FIG. 2. Theobtaining unit 201 obtains the information bit sequence and the targetcode length M of the polar code. The target code length may bedetermined based on a quantity K of the information bits and an adoptedcode rate R. For example, if the quantity of information bits is 20, andthe code rate is 1/8, the target code length is 160.

302. Select a mother code length based on a preset condition, and polarencoding the information bit sequence.

Specifically, when the target code length M meets the preset condition,the encoding unit 202 uses a polar code with a first mother code lengthN₁ to encode the information bit sequence, to output a first encoded bitsequence with a length N₁. N₁ is less than or equal to M, and N₁ is aninteger power of 2.

When the target code length M does not meet the preset condition, theencoding unit 202 uses a polar code with a second mother code length N₂to encode the information bit sequence, to output a second encoded bitsequence with a length N₂. N₂ is greater than or equal to M, and N₂ isan integer power of 2.

303. Determine a rate matching manner based on the mother code lengthused in step 302, and perform rate matching.

When the target code length M meets the preset condition, because themother code length N₁ used in step 302 is less than or equal to thetarget code length, the rate matching unit 203 repeats at least somebits in the first encoded bit sequence, to obtain a first target polarcode with a length M.

When the target code length M does not meet the preset condition, themother code length N₂ used in step 302 is greater than or equal to thetarget code length, and correspondingly, the rate matching unit 203shortens or punctures the second encoded bit sequence, to obtain asecond target polar code with a length M.

When a repetition manner is used in rate matching, repetition may beperformed according to a predetermined order, until the target codelength M is obtained, to obtain the target polar code. The predeterminedorder may be any one of the following:

-   -   an order from back to front,    -   an order from front to back,    -   a random order,    -   a bit reversal order from back to front,    -   a bit reversal order from front to back,    -   a descending order of reliability, or    -   any other orders.

The bit reversal order is to convert a decimal integer (an index of anencoded bit) into a binary form, negate an order of elements of a binarydigit, and convert the negated binary digit into a decimal digit. Thenewly obtained digit is a bit reversal order value of an original digit.The reliability herein is reliability of a polarized channelcorresponding to an encoded bit. Performing repetition based on adescending order of reliability indicates that a more important encodedbit is to be preferentially repeated.

N₁ encoded bits may be stored, according to the foregoing preset rule,in a cyclic buffer shown in FIG. 4, and the encoded bits are read fromthe cyclic buffer in order during rate matching, until the target codelength M is obtained. Assuming that N₁ is 128, and M is 160, 32 encodedbits need to be repeated. 128 encoded bits are arranged based onreliability and then stored in the cyclic buffer. The first to 128^(th)bits are read in order, and 32 bits are then read, to obtain a polarcode with a length 160.

That the target code length M meets the preset condition described instep 302 and step 303 may be that a first code rate Ri determined basedon the quantity K of information bits and the first mother code lengthN₁ is less than or equal to a preset second code rate R₂. The first coderate R₁ herein is equal to K/N₁. K is the quantity of information bits,N₁=2^(n), and n is an integer less than or equal to log₂ M. To bespecific, N₁ is an integer power of 2 and less than or equal to thetarget code length M. The second code rate is a code rate threshold andused to determine the rate matching manner.

To be specific, if R₁≤R₂, the first mother code length N₁ less than thetarget code length is used for encoding, to output the N₁ encoded bits,and at least some of the N₁ encoded bits are repeated, to obtain thetarget polar code with the length M. If R₁>R₂, a minimum integer powerof 2 that is greater than or equal to the target code length is used asthe second mother code length N₂, to encode the information bit sequenceand output N₂ encoded bits, and the N₂ encoded bits are shortened orpunctured, to obtain the second target polar code with the length M. Themother code length is determined by comparing the first code rate andthe second code rate. Correspondingly, the rate matching manner isdetermined. The second code rate may also be referred to as a mothercode code rate threshold. A value of the mother code code rate thresholdmay be set depending on an actual application case. In this embodimentof this application, the mother code code rate threshold may be flexiblyset to a value between 0 and 1 depending on an application scenario. Forexample, a value of R₂ includes but is not limited to 1/3, 1/4, 1/5,1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 2/7, 3/8, 2/9, 3/10, 2/11, or3/11. The value of R₂ is neither limited to the examples listed herein,nor limited to a fraction form used herein, and may be set to a valuewith a decimal point such as 0.167.

Determining of the code rate threshold may balance an encoding gain andcomplexity. FIG. 5 shows a performance comparison between a repetitionrate matching manner and a shortening manner that are used in anadditive white Gaussian noise (AWGN) channel when a quantity ofinformation bits is 40 and different code rates are used. A target codelength M corresponding to two solid lines is 224. A square box indicatesthat a repetition rate matching manner is used, 128 bits (the firstmother code length N₁) are obtained through encoding, and 96 bits arerepeated, to obtain 224 bits (the target code length). An asterisk “*”indicates that a shortening rate matching manner is used, and 256 bits(the second mother code length N₂) are obtained through encoding and areshortened by 32 bits to obtain 224 bits (the target code length). Thatthe code rate threshold R₂ is equal to 1/4 is used as an example.

In this case, R₁=K/N₁=40/128>1/4, and R₁≤R₂ is not met. Therefore, apuncturing or shortening manner may be used to perform rate matching. Itcan be learned that, when a block error rate is 10⁻³, an encoding gainloss in the repetition-based rate matching manner is approximately 0.3dB. When a code rate is higher, a mother code length is smaller, and anencoding gain loss is higher. Therefore, when the first code rate isgreater than the code rate threshold, the shortening or puncturingmanner is suitable.

A target code length corresponding to two dashed lines in FIG. 5 is 288.An asterisk “*” indicates that a repetition rate matching manner isused, 256 bits (the first mother code length N₁) are obtained throughencoding, and 32 bits are repeated, to obtain 288 bits. A circle “o”indicates that a shortening rate matching manner is used, and 512 bits(the second mother code length N₂) are obtained through encoding and areshortened by 224 bits to obtain 288 bits. It can be learned that anencoding gain in the repetition-based rate matching manner is equivalentto that in the shortening-based rate matching manner; however, themother code length in the repetition-based rate matching manner is halfof that in the shortening-based rate matching manner. Therefore,encoding and decoding delays and complexity in the repetition-based ratematching manner are significantly lower than those in theshortening-based rate matching manner. That the code rate threshold R₂is equal to 1/4 is used as an example. In this case, R₁=K/N₁=40/256<1/4,and the preset condition R₁≤R₂ is met. Therefore, the repetition-basedrate matching manner is determined. When a code rate is lower, a codelength is larger, and encoding gains are closer; however, therepetition-based rate matching manner can reduce complexitysignificantly and reduce a delay.

In this embodiment of this application, N₁=2^(n), where n is an integerless than or equal to log₂ M. For example, when M=224, 7 is obtained byperforming rounding on log₂ M, and in theory, a value of n may rangefrom 1 to 7. In the example shown in FIG. 5, in the repetition-basedrate matching manner, a maximum integer less than or equal to log₂ M isselected for n. To be specific, N₁=2⁷=128. In this case, R₁>R₂. If asmaller value is determined for N₁, R₁ is larger, and R₁ is definitelygreater than R₂. If R₂ is set to 1/6, R₁>R₂. In this case, no availablevalue of N₁ can meet the repetition-based rate matching manner. Foranother example, when M=288, 8 is obtained by performing rounding onlog₂ M, and in theory, a value of n may range from 1 to 8. In theexample shown in FIG. 5, in the repetition-based rate matching manner, amaximum integer less than or equal to log₂ M is determined for n. To bespecific, 2⁸=256, and the condition R₁≤R₂ is met. In this case, if N₁ isequal to 128, the condition R₁≤R₂ is not met. If the code rate thresholdR₂ is set to 1/7, regardless of whether N₁ is equal to 256 or 128, thecondition R₁≤R₂ is not met. In this case, the shortening or puncturingrate matching manner is used.

For another example, it is assumed that the quantity K of informationbits is equal to 200, the target code length M is equal to 2400, and thecode rate threshold R₂ is equal to 1/4. A maximum value of N₁ may be2048, 1024, 512, or the like. R₁ is respectively 200/2048, 200/1024, or200/512. When N₁ is 2048 or 1024, R₁≤R₂ is met, and the repetition-basedrate matching manner may be used. When at least two mother code lengthsmeet the preset condition, a mother code length with lowest encoding anddecoding complexity, that is, a minimum mother code length, may bedetermined. In this example, if both 2048 and 1024 meet the presetcondition, 1024 is determined as the value of N₁. In other words, whenit is determined that the repetition-based rate matching manner is to beused, a minimum candidate mother code length that meets the presetcondition is preferentially determined as the first mother code length.

In this embodiment of this application, provided that the value of N₁can meet R₁≤R₂, the repetition-based rate matching manner is determined;and only when no value of N₁ meets R₁≤R₂, the shortening or puncturingrate matching manner is used.

That the target code length M meets the preset condition described instep 302 may be: It is determined that the target code length M isgreater than or equal to a preset maximum mother code length N_(max). Avalue of N_(max) may be flexibly set, depending on an actual applicationscenario, to an integer power of 2, such as 2048, 1024, 512, 256, 128,64, or 32. This is not limited. Herein, the value of N_(max) has noupper limit, but is determined depending on an application scenario. Forexample, in some application scenarios, for example, in a data channel,if the target code length reaches 6000 or 12000, the value of N_(max)may be larger. For example, the value may be 4096 or 8192. If it isdetermined that the repetition manner is to be used to perform ratematching and the first mother code length is N_(max), a transmitting endconstructs and encodes a polar code with a length N_(max), and repeats(M-N_(max)) bits, to obtain the first target polar code with the targetcode length M. A receiving end combines an LLR signal at a repetitionlocation, restores a received signal to the mother code length N_(max),and then performs decoding.

For example, N_(max)=2048, the target code length M is equal to 600, andM<N_(max). In this case, the shortening or puncturing manner is used toperform rate matching, and a minimum integer power of 2 that is greaterthan 600, namely, 1024, is determined as a mother code length. A polarcode is constructed based on the mother code length 1024 and the targetcode length 600, and 1024 bits are obtained through encoding and areshortened or punctured by 424 bits, to obtain target 600 bits.

For example, N_(max)=1024, the target code length M is equal to 2400,and M>N_(max). In this case, the repetition manner is used to performrate matching, and it is determined that the mother code length is 1024.A polar code is constructed based on the mother code length 1024, 1024bits are obtained through encoding, and 1376 bits are obtained throughrepetition, to obtain a 2400-bit target polar code. If N_(max)=2048,M>N_(max) is still met. A polar code may be constructed based on thecode length 2048, 2048 bits are obtained through encoding, and 352 bitsare repeated, to obtain a 2400-bit target polar code.

If in a system, a maximum quantity of information bits is 200, and aminimum code rate is 1/12, a target code length is 2400. According to aconventional rate matching manner, encoding needs to be performed until4096 bits are obtained, and then puncturing or shortening is performed,to obtain 2400 bits. According to the solutions in this application, anencoding gain is considered. 2048/1024 bits are obtained throughencoding, and then 2400 bits are obtained through repetition. Comparedwith the conventional rate matching manner, there is almost no encodinggain loss (when 1024 bits are obtained through encoding, an encodinggain loss is within 0.1 dB). However, from a perspective of complexity,compared with a buffer for performing encoding to obtain 4096 bits, abuffer for performing encoding to obtain 2048 or 1024 bits is decreasedto 1/2 or 1/4. Operation complexity is significantly reduced, and adecoding delay may be decreased by approximately 20% or 50%.

FIG. 6 shows a performance comparison between a repetition-based ratematching manner and a shortening-based rate matching manner that areused in an AWGN channel. A quantity K of information bits is equal to200. In this figure, a target code length M corresponding to a solidline group is 1184. A mother code length corresponding to a square boxis 1024, and 160 bits are repeated, to obtain 1184 bits. A mother codelength corresponding to either an asterisk “*” or a circle “o” is 2048,and 1184 bits are obtained through shortening. It can be learned fromFIG. 6 that an encoding gain in the repetition-based rate matchingmanner is equivalent to that in the shortening-based rate matchingmanner.

A target code length corresponding to a dashed line group in FIG. 6 is2400. A mother code length corresponding to a square box is 1024, and1376 bits are obtained through repetition, to obtain 2400 bits. A mothercode length corresponding to an asterisk “*” is 2048, and 352 bits arerepeated, to obtain 2400 bits. A mother code length corresponding to acircle “o” is 4096 bits, and 2400 bits are obtained through shortening.It can be learned from FIG. 6 that an encoding gain based on 2048 bitsin the repetition-based manner is equivalent to that in theshortening-based manner, and an encoding gain loss based on 1024 bits inthe repetition-based manner is within 0.05 dB compared with that in theshortening-based manner. However, compared with the shortening manner,when the target code length is not an integer power of 2, the mothercode length used in the repetition-based rate matching manner isdecreased by at least a half. Therefore, a size of a required buffer canbe significantly reduced, encoding and decoding operation complexity isreduced, and a delay is reduced.

Puncturing described in this embodiment of this application includesquasi-uniform puncture (QUP). First, it is determined that the mothercode length is an integer power of 2 that is greater than or equal tothe target code length. Then, a puncturing (a puncturing location) isdetermined based on the mother code length and the target code length.

The puncturing mode may be indicated by using a binary sequence (00 . .. 011 . . . 1), and it is determined that “0” indicates a puncturinglocation and “1” indicates a location that is not punctured. A channelcapacity corresponding to the puncturing location is set to 0 (or anerror probability is set to 1, or a signal-to-noise ratio (SNR) is setto be infinitesimal). Reliability of polarized channels is calculated byusing a method such as density evolution, Gaussian approximation, orlinear fitting and is sorted, to determine locations of an informationbit and a fixed bit (a frozen bit). An encoder side deletes an encodedbit that is at the puncturing location, to obtain a polar code.

A polar code shortening described in this application is as follows: Itis determined that the mother code length is an integer power of 2 thatis greater than or equal to the target code length. An encoded bit at ashortening location is only related to a fixed bit. A process includes:Reliability of polarized channels is calculated based on a mother code,then a shortening location is determined, a fixed bit is placed in acorresponding polarized channel, locations of an information bit and afrozen bit (a fixed bit) in a remaining polarized channel are determinedbased on the reliability, and an encoded bit at the shortening locationis deleted, to obtain a polar code, and to implement rate matching.According to the shortening-based rate matching manner, the reliabilityof the polarized channels does not need to be recalculated based on theshortening location, but the fixed bit is placed in the polarizedchannel corresponding to the shortening location. This greatly reducescomplexity of constructing a polar code.

As shown in FIG. 7, this application provides another communicationsapparatus 700 that can implement encoding and rate matching. Thecommunications apparatus 700 includes: a transceiver 701, configured tocommunicate with another device; a memory 702, configured to store aprogram; and a processor 703, configured to execute the program storedin the memory. When the program is executed, the processor is configuredto: when a target code length M during polar encoding meets a presetcondition, use a polar code with a first mother code length N₁ to encodean information bit sequence, to output a first encoded bit sequence,where N₁ is less than or equal to M, and N₁ is an integer power of 2,and repeat at least some bits in the first encoded bit sequence, toobtain a first target polar code with a length M; or when the targetcode length M does not meet the preset condition, use a polar code witha second mother code length N₂ to encode the information bit sequence,to output a second encoded bit sequence, where N₂ is greater than orequal to M, and N₂ is an integer power of 2, and shorten or puncture thesecond encoded bit sequence, to obtain a second target polar code with alength M. The transceiver 701, the memory 702, and the processor 703 areconnected by using a bus.

Determining whether the target code length M meets the preset conditionand a corresponding rate matching implementation are the same as thosedescribed above. Whether a repetition or a shortening or puncturing isused may be determined by using a mother code code rate threshold or amaximum mother code length, so that an encoding gain and complexity arebalanced. A repetition process and a shortening or puncturing processmay be the same as those described above.

In some embodiments, the communications apparatus has both encoding anddecoding functions. When serving as a sender, the communicationsapparatus performs an encoding and rate matching procedure. When servingas a receiver, the communications apparatus performs a rate de-matchingand decoding procedure. The communications apparatus includes a basebandchip. The baseband chip includes an encoder and a decoder. The encodermay be configured to perform a function that is the same as that of theforegoing encoding apparatus, and the decoder may perform a functionthat is the same as that of the foregoing decoding apparatus. Thecommunications apparatus includes a device that has a bidirectionalwireless communications function, such as a base station or userequipment.

A decoding apparatus 800 shown in FIG. 8 may be configured to performrate de-matching and decoding in this application. The decodingapparatus 800 includes a receiving unit 801, a rate de-matching unit802, and a decoding unit 803. As shown in FIG. 9, a rate de-matching anddecoding process includes the following steps.

901. Receive a log-likelihood ratio (LLR) of a to-be-decoded bitsequence with a length M, where M is a target code length during polarencoding.

The receiving unit 801 receives the LLR of the to-be-decoded bitsequence with the length M, where M is the same as the target codelength used by an encoder side to perform polar encoding.

902. Determine, based on the target code length M, a rate matchingmanner used by an encoder side, and perform rate de-matching.

When the target code length M meets a preset condition, a ratede-matching unit 802 determines that a transmitting end uses arepetition manner to perform rate matching, determines a location of arepeated bit, and adds and combines an LLR, at a repetition location, inreceived LLRs of M bits, to obtain an LLR of a first to-be-decoded bitsequence whose length is a first mother code length N₁, where N₁ is lessthan or equal to M, and N₁ is an integer power of 2.

When the target code length M does not meet the preset condition, therate de-matching unit 802 determines that the encoder side uses ashortening or puncturing method to perform rate matching, determines ashortening or puncturing location and an LLR at the shortening orpuncturing location, and restores LLRs, received by the receiving unit801, of M bits to a second mother code length N₂, to obtain an LLR of asecond to-be-decoded bit sequence whose length is the second mother codelength N₂, where N₂ is greater than or equal to M, and N₂ is an integerpower of 2.

If the encoder side uses the repetition manner to perform rate matching,a decoder side correspondingly performs rate de-matching according to arepetition rule preset by both the encoder side and the decoder side.For example, if the repetition rule of the encoder side is in an orderfrom back to front, during rate matching, LLRs of last M-N₁ bits in theM bits are added and combined, to obtain LLRs of N₁ to-be-decoded bits.

If the encoder side uses the shortening manner to perform rate matching,the rate de-matching unit 802 uses a bit at the shortening location as aknown bit, sets a corresponding LLR to be infinite, and restores theLLR, together with a received LLR at a location that is not shortened,to a mother code length.

If the encoder side uses the puncturing manner to perform rate matching,the rate de-matching unit 802 uses a bit corresponding to a puncturinglocation as an unknown bit for processing, sets a correspondinglog-likelihood ratio to 0, and restores the log-likelihood ratio,together with a received LLR at a location that is not punctured, to amother code length.

903. Perform polar decoding based on the LLR of the to-be-decoded bitsequence that has undergone rate de-matching.

When the target code length M meets the preset condition, a decodingunit 803 correspondingly performs polar decoding based on the LLR of thefirst to-be-decoded bit sequence.

When the target code length M does not meet the preset condition, thedecoding unit 803 correspondingly performs polar decoding based on theLLR of the second to-be-decoded bit sequence.

Like the encoder side, that the target code length M meets the presetcondition described in step 902 and step 903 may be that a first coderate R₁ determined based on a quantity K of information bits and thetarget code length M is less than or equal to a preset second code rateR₂. The first code rate R₁ herein is equal to K/N₁. K is the quantity ofinformation bits, N₁=2^(n), and n is an integer less than or equal tolog₂ M. A determination process of N₁ is the same as that on the encoderside. The second code rate may also be referred to as a mother code coderate threshold and is preset on the encoder side and the decoder side. Avalue of R₂ is the same as that on the encoder side, and may be 1/4 or1/6. For example, R₂ on the encoder side is 1/4, and is also 1/4 on thedecoder side. When R₁≤R₂, it is determined that the encoder side uses arepetition rate matching manner, and a used mother code length is N₁.When R₁>R₂, it is determined that the encoder side uses a shortening orpuncturing manner.

Alternatively, the preset condition may be as follows: A maximum mothercode length N_(max) is set, and the target code length M is comparedwith the maximum mother code length. If M≥N_(max) is met, it isdetermined that the transmitting end uses the repetition manner toperform rate matching, and therefore the decoder sidecorrespondinglymanner performs rate de-matching. If M<N_(max), it isdetermined that the transmitting end uses the shortening or puncturingmanner to perform rate matching, and the decoder side correspondinglyperforms rate de-matching. Like the encoder side, N_(max) may be set toan integer power of 2, such as 2048, 1024, 512, 256, 128, 64, or 32.This is not limited.

The encoder side and the decoder side may preset to use the shorteningrate matching manner or the puncturing rate matching manner when thetarget code length M does not meet the preset condition. For example,the shortening manner is uniformly used, or the puncturing manner isuniformly used.

A communications apparatus shown in FIG. 7 may also be configured toperform a rate de-matching and decoding process. The communicationsapparatus includes: a transceiver 701, configured to communicate withanother device; a memory 702, configured to store a program; and aprocessor 703, configured to execute the program stored in the memory701. When the program is executed, the processor 703 is configured to:when a target code length M during polar encoding meets a presetcondition, determine that a transmitting end uses a repetition manner toimplement rate matching; determine a location of a repeated bit; add andcombine an LLR, at a repetition location, in received LLRs of M bits, toobtain an LLR of a first to-be-decoded bit sequence whose length is afirst mother code length N₁, where N₁ is less than or equal to M, and N₁is an integer power of 2; and perform polar decoding based on the LLR ofthe first to-be-decoded bit sequence.

Alternatively, the processor 703 is configured to: when the target codelength M does not meet the preset condition, determine that thetransmitting end uses a shortening or puncturing method to implementrate matching; determine a shortening or puncturing location and an LLRat the shortening or puncturing location; restore the received LLRs of Mbits to a second mother code length N₂, to obtain an LLR of a secondto-be-decoded bit sequence whose length is the second mother code lengthN₂, where N₂ is greater than or equal to M, and N₂ is an integer powerof 2; and perform polar decoding based on the LLR of the secondto-be-decoded bit sequence.

Determining whether the target code length M meets the preset conditionand a corresponding rate de-matching implementation are the same asthose described above. Whether an encoder side uses a repetition-basedrate matching manner or a shortening or puncturing rate matching mannermay be determined by using a mother code code rate threshold or amaximum mother code length.

The solutions in this application may be used in a control channel or adata channel. A relatively small quantity of information bits need to besent in the control channel. Therefore, in an embodiment, when encodingand decoding are performed, code lengths (mother code lengths) and ratematching manners used in various cases may be listed depending onwhether the target code length meets the preset condition described inthis application, and stored on an encoder side and a decoder side. Inother words, the encoder side and the decoder side do not need todetermine whether the target code length meets the preset condition.Instead, the encoder side and the decoder side directly read acorresponding parameter from a configured parameter according to aspecified rule to perform encoding, rate matching, and correspondingrate de-matching and decoding. In an example, assuming that a manner ofthe mother code code rate (a code rate for encoding) threshold is usedand a code rate threshold R₂ is set to 1/4, a configured encodingparameter may be stored in a form shown in Table 1. In this case, aquantity of information bits, a target code length, a mother codelength, and a rate matching manner have been determined according to apreset rule. Alternatively, the rate matching manner may not be shown.If the mother code length is less than or equal to the target codelength, it is determined that the repetition rate matching manner isused. If the mother code length is greater than the target code length,it is determined that the shortening or puncturing manner is used. Theencoder side and the decoder side may uniformly specify whether theshortening manner or the puncturing manner is used and a correspondingshortening mode or puncturing mode. Certainly, the rate matching mannermay alternatively be shown in the configured parameter. How to performrepetition may also be configured on the encoder side and the decoderside.

TABLE 1 Quantity K of Target code Mother code information bits length Mlength N Rate matching manner . . . . . . . . . . . . 40 224 256Shortening or puncturing 40 288 256 Repetition . . . . . . . . . . . .200 2400 1024 Repetition 200 1200 1024 Repetition 200 800 1024Shortening or puncturing

Provided that the preset condition is determined, a mother code lengthand a rate matching manner used in each case can be determined. Forexample, when R₂ is 1/6, encoding parameters and rate matching mannersused in different cases may be determined.

The communications apparatus described in this embodiment of thisapplication may be a wireless communications device such as an accesspoint, a station, a base station, or a user terminal.

A polar code described in this embodiment of this application includes,but is not limited to, an Arikan polar code, or may be a CA-polar codeor a PC-polar code. The Arikan polar code is an original polar code, isnot cascaded with another code, and has only an information bit and afrozen bit. The CA-polar code is a polar code cascaded with a cyclicredundancy check (CRC). The PC-polar code is a polar code cascaded witha parity check (PC) code. The PC-polar code and the CA-polar codeimprove performance of a polar code by cascading different codes.

An “information bit sequence” described in this embodiment of thisapplication may also be referred to as a “to-be-encoded bit sequence” oran “information bit set”. Correspondingly, the “quantity of informationbits” may be a quantity of to-be-encoded bits in the to-be-encoded bitsequence or a quantity of elements in the information bit set.

That the target code length M meets the preset condition described inthis application may be further that a difference between the targetcode length M and the first mother code length N₁ is less than a presetrange. N₁ is less than or equal to M, and N₁ is an integer power of 2.For example, the preset condition may be M≤N₁*(1+δ). If the mother codelength N₁ meets the condition, it is determined that therepetition-based rate matching manner is used, the first mother codelength N₁ is used to perform polar encoding, to obtain a first encodedbit sequence, and at least some bits in the first encoded bit sequenceare repeated, to obtain an encoded bit sequence with the target codelength. If the condition is not met, the shortening-based orpuncturing-based rate matching manner is used. The foregoing presetcondition may be further indicated as

${\frac{M}{N_{1}} \leq \left( {1 + \delta} \right)},{{M - N_{1}} \leq {N_{1}*\delta}},{{{or}\mspace{14mu} \frac{M - N_{1}}{N_{2}}} \leq {\delta.}}$

δ may be a constant, for example, may be set to 1/8, 1/4, or 3/8.

δ may be a value related to a code rate. δ=FUNCTION(R₁) is a function of

$R_{1} = {\frac{K}{N_{1}}.\mspace{11mu} \delta}$

usually decreases as R₁ increases, and K is the quantity of informationbits. In other words, a value of δ is related to the quantity ofinformation bits and the mother code length.

In an implementation, a function of δ relative to a code rate R₁ may bedesigned as δ=β*(1−R₁). δ is a preset constant. For example, β may be1/2, 3/8, 1/4, 1/8, or 1/16. In other words, δ is a linear function ofR₁. Larger R₁ results in smaller δ, and a smaller quantity of bits areallowed to be repeated.

Assuming that M=160, K=80, β=1/2, and N₁=128, R₁=80/128=0.625, andδ=1/2*(1−80/128)=0.1875. M≤N₁*(1+δ) is used to determine whether to usethe repetition rate matching, and N₁*(1+δ)=128*(1+0.1875)=152. BecauseM=160>152, and M≤N₁*(1+δ) is not met, the repetition rate matchingmanner is not used. Instead, another manner such as the shortening orpuncturing manner may be used. In the foregoing parameters, if K=32 andother parameters keep unchanged, R₁=32/128=1/4, δ=1/2*(1−1/4)=3/8,N₁*(1+δ)=128*(1+3/8)=176, M=160<176, and M≤N₁*(1+δ) is met. Therefore,the repetition-based rate matching manner is used. To be specific, thefirst mother code length is 128. An encoded bit sequence with a length128 is obtained through encoding, and 32 bits in the encoded bitsequence are repeated, to obtain a target code length 160.

In another implementation, a function of δ relative to a code rate R maybe designed as δ=β*(1-R₁)². β is a constant. For example, β may be 1/2.To be specific, δ is a quadratic function of R₁. Larger R₁ results insmaller δ, and a smaller quantity of bits are allowed to be repeated.Assuming that M=160, K=80, δ=1/2, and N₁=128, R₁=80/128=0.625, andδ=1/2*(1−80/128)²=0.0703125. M>N₁*(1+δ) is used to determine whether touse the repetition rate matching, and N₁*(1+δ)=128*(1+0.0703125)=137.Because M=160>137, and M≤N₁*(1+δ) is not met, the repetition ratematching manner is not used. Instead, another manner such as theshortening or puncturing manner may be used. In the foregoingparameters, if K=32 and other parameters keep unchanged, R₁=32/128=1/4,δ=1/2*(1−1/4)²=9/32, N₁*(1+δ)=128*(1+9/32)=164, M=160<164, andM≤N₁*(1+δ) is met. Therefore, the repetition-based rate matching manneris used. To be specific, the first mother code length is 128. An encodedbit sequence with a length 128 is obtained through encoding, and 32 bitsin the encoded bit sequence are repeated, to obtain a target code length160.

In another implementation, a function of 6 relative to a code rate R₁may be designed as:

$\begin{matrix}{\delta = \left\{ \begin{matrix}{a,} & {{{if}\mspace{14mu} R_{1}} < R_{3}} \\{0,} & {{{if}\mspace{14mu} R_{1}} \geq R_{3}}\end{matrix} \right.} & {{Formula}\mspace{14mu} (1)}\end{matrix}$

δ is a piecewise function determined based on R₁. If R₁ is less than apreset threshold R₃, a value of δ is a, a is a constant, and a value ofa may be 1/16, 1/4, 3/8, 1/2, or the like. If R₁ is greater than orequal to the threshold R₃, a value of δ is 0. R₃ may be 1/4 or 1/6, ormay be 1/3, 1/4, 1/5, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 2/7, 3/8, 2/9,3/10, 2/11, 3/11, or the like. Assuming that M=160, K=80, R₃=1/4, andN₁=128, R₁=80/128=0.625>1/4, and δ=0 based on the formula (1).M≤N₁*(1+δ) is used to determine whether to use the repetition ratematching, and N₁*(1+δ)=128*(1+0)=128. Because M=160>128, and M≤N₁*(1+δ)is not met, the repetition rate matching manner is not used. Instead,another manner such as the shortening or puncturing manner may be used.In the foregoing parameters, if K=32 and other parameters keepunchanged, R₁=32/128=1/4=R₃, a value of δ is 0, and the repetition ratematching manner is not used. If R₃=1/6, R₁=32/128=1/4<R₃, a value of δis 1/8, N₁*(1+δ)=128*(1+1/8)=144, M=160>144, and M≤N₁*(1+δ) is not met.Therefore, the repetition rate matching manner is not used. Instead,another manner such as the shortening or puncturing manner may be used.If in the formula (1), R₁<R₃, and a value of δ is 1/2,N₁*(1+δ)=128*(1+1/2)=192, M=160<192, and M<N₁*(1+δ) is met. Therefore,the repetition-based rate matching manner is used. To be specific, thefirst mother code length is 128, an encoded bit sequence with a length128 is obtained through encoding, and 32 bits in the encoded bitsequence are repeated, to obtain a target code length 160.

FIG. 10 shows a performance comparison between a repetition-based mannerand a puncturing-based manner that are used when M=160 and K hasdifferent values. A dashed line indicates that the repetition-based ratematching manner is used, and a solid line indicates that thepuncturing-based rate matching manner is used. The target code length isset to a fixed value 160. The target code length may be obtained byperforming puncturing based on 256 (the solid line) or obtained byperforming repetition based on 128 (the dashed line). If repetition isperformed based on 128, a quantity of bits that need to be repeated is(160-128), that is, 32, and a repetition proportion is 32/128=1/4. Itcan be learned from FIG. 10 that when quantities of information bits aredifferent, that is, code rates are different, performance of therepetition manner is different from performance of the puncturingmanner. When a code rate is high (K is relatively large, for example,K=80), compared with the puncturing manner, the repetition manner has anobvious performance loss (approximately 0.7 dB). When a code rate is low(K is relatively small, for example, K=20 or K=40), performance of therepetition manner is equivalent to performance of the puncturing manner.Therefore, a value of δ is determined based on a code rate, and δdecreases as R₁ increases. When performance losses are equivalent orslightly different, the repetition rate matching is used, so that adesirable balance is achieved between an encoding gain loss andcomplexity.

This application provides a plurality of embodiments to determinewhether the target code length M meets the preset condition. In anotherembodiment, a minimum value may be determined as a value of the firstmother code length from all values of N₁ that meet any one of theforegoing preset conditions, and the repetition-based rate matchingmanner is used. If no value of the first mother code length meets thepreset condition, the shortening or puncturing manner is used. Assumingthat M=576 and K=20, a set of values of N₁ corresponding to cases inwhich the repetition-based rate matching manner is allowed to be used isobtained based on different preset conditions.

A preset condition 1: A first code rate R₁ determined based on thequantity K of the information bits and the target code length M is lessthan or equal to a preset second code rate R₂, and R₁=K/N₁. Herein, avalue of R₂ is 1/4, and based on R₁=K/N₁, a value of N₁ that meets R₁<R₂is 512, 256, or 128.

A preset condition 2:

The target code length is greater than a preset maximum mother codelength N_(max), and N_(max) is 512. Based on M=576>512, the presetcondition is met, the repetition-based rate matching manner is used, andN₁=512.

A preset condition 3:

A difference between the target code length M and the first mother codelength N₁ is less than the preset range, and indicated by M≤N₁*(1+δ). Avalue of δ is determined by using the formula (1), a=1/8, and R₃=1/6. IfN₁=512, R₁=20/512<R₃, and δ is 1/8, N₁*(1+δ)=576, M=N₁*(1+δ), and thepreset condition is met. If N₁=256, R₁=20/256<R₃, and δ is 1/8,N₁*(1+δ)=288, M>N₁*(1+δ), and the preset condition is not met.Therefore, a value of N₁ that is determined based on the presetcondition 3 and that allows use of the repetition-based rate matchingmanner is 512.

A set of values of N₁ obtained based on the foregoing three presetconditions is {128, 256, 512}. The repetition-based rate matching manneris used, the minimum value 128 is determined as the value of the firstmother code length, an encoded bit sequence with a length 128 isobtained through encoding, and the encoded bit sequence is repeated, toobtain a target code length 576. Parameters in the foregoing threepreset conditions may be flexibly set with reference to the embodimentsprovided in this application.

Units and method processes in the examples described in the embodimentsof this application can be implemented by electronic hardware or acombination of computer software and electronic hardware. Whether thefunctions are performed by hardware or software depends on particularapplications and design constraint conditions of the technicalsolutions. Different methods may be used to implement the describedfunctions for each particular application.

In the several embodiments provided in this application, it should beunderstood that the disclosed apparatus and method may be implemented inother manners. For example, the described apparatus embodiments aremerely examples. For example, the unit division is merely logicalfunction division and may be other division during actualimplementation. For example, a plurality of units or components may becombined or integrated into another system, or some steps may be ignoredor not performed. In addition, couplings or direct couplings orcommunications connections between the units may be implemented inelectrical, mechanical, or other forms.

The units described as separate parts may or may not be physicallyseparate, may be located in one position, or may be distributed on aplurality of network units.

In addition, functional units in the embodiments of this application maybe integrated into one processing unit, or each of the units may existalone physically, or two or more units may be integrated into one unit.

All or some of the foregoing embodiments may be implemented by usingsoftware, hardware, firmware, or any combination thereof. When thesoftware is used to implement the embodiments, all or some of theembodiments may be implemented in a form of a computer program product.The computer program product includes one or more computer instructions.When the computer program instructions are loaded and executed on acomputer, all or some of the procedures or functions in the embodimentsof the present invention are generated. The computer may be ageneral-purpose computer, a special-purpose computer, a computernetwork, or another programmable apparatus. The computer instructionsmay be stored in a computer readable storage medium, or transmitted byusing the computer readable storage medium. The computer instructionsmay be transmitted from a website station, a computer, a server, or adata center to another website station, computer, server, or data centerin a wired (for example, a coaxial cable, an optical fiber, or a digitalsubscriber line (DSL)) or wireless (for example, an infrared ray, radio,or a microwave) manner. The computer readable storage medium may be anyavailable medium that can be accessed by a computer, or may be a datastorage device such as an integrated server including one or moreavailable media (for example, a cloud server) or a data center. Theavailable medium may be a magnetic medium (for example, a floppy disk, ahard disk, a magnetic tape, a USB flash drive, a ROM, or a RAM), anoptical medium (for example, a CD or a DVD), or a semiconductor medium(for example, a solid state disk (SSD)).

What is claimed is:
 1. A method for encoding data, performed by a devicein a wireless communication network, comprising: obtaining, by thedevice, K data bits and a target code length M, wherein K, M arepositive integers; determining, by the device, a mother code length N₁according to a minimum value of values N_(a), N_(max) and N, and N₁ isan integer power of 2; polar encoding, by the device, the K data bits toobtain an encoded bit sequence, wherein the encoded bit sequence has acode langth of N₁; and outputting, by the device, the encoded bitsequence; wherein the values N_(a), N_(max) and N satisfy the followingconditions: the value N_(a) satisfies with: a rate R₁ is less than orequal to a preset rate, wherein the rate R₁ is determined according tothe value K and the value N_(a); the value N_(max) is a preset maximummother code length, wherein N_(max) is an integer power of 2; and thevalue N satisfies with M≤N*(1+δ), wherein δ is a preset constant.
 2. Themethod according to claim 1, wherein N₁=2^(n), and n is a maximum valueof integers less than or equal to log₂ M.
 3. The method according toclaim 1, wherein the preset rate is one of: 1/2, 1/3, 1/4, 1/5, 1/6,1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 2/7, 3/8, 2/9, 3/10, 2/11, and 3/11. 4.The method according to claim 1, wherein the value N_(max) is one of:2048, 1024, and
 512. 5. The method according to claim 1, wherein theconstant δ is one of: 1/8, 1/4, and 3/8.
 6. The method according toclaim 1, wherein polar encoding the K data bits to obtain the encodedsequence comprises: generating a binary row vector u₁ ^(N) ¹ , whereinu₁ ^(N) ¹ =(u₁, u₂, . . . u_(N) ₁ ), and K bit-positions of the binaryrow vector u₁ ^(N) ¹ are occupied by the K data bits; and encoding thebinary row vector u₁ ^(N) ¹ according to an encoding formula, to obtainthe encoded bit sequence; wherein the encoding formula is:x₁ ^(N) ¹ =u₁ ^(N) ¹ G_(N1) wherein x₁ ^(N) ¹ =(x₁, x₂, . . . x_(N) ₁ )is the encoded bit sequence, and G_(N) ₁ is a polar code generatingmatrix of N₁ row and N₁ columns.
 7. A device in a wireless communicationnetwork, comprising a processor and a memory storing programinstructions for execution by the processor; wherein when executed bythe processor, the program instructions cause the device to: obtain Kdata bits and a target code length M, wherein K, M are positiveintegers; determine a mother code length N₁ according to a minimum valueof values N_(a), N_(max) and N, and N₁ is an integer power of 2; polarencode the K data bits according to the first mother code length N₁, toobtain an encoded bit sequence, wherein the encoded bit sequence has acode length of N₁; and output the encoded bit sequence; wherein thevalues N_(a), N_(max) and N satisfy the following conditions: the valueN_(a) satisfies with: a rate R₁ is less than or equal to a preset rate,wherein the rate R₁ is determined according to the value K and the valueN_(a); the value N_(max) is a preset maximum mother code length, whereinN_(max) is an integer power of 2; and the value N satisfies withM≤N*(1+δ), wherein δ is a preset constant.
 8. The device according toclaim 7, wherein N₁=2^(n), and n is a maximum value of integers lessthan or equal to log₂ M.
 9. The device according to claim 7, wherein thepreset rate is one of: 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10,1/11, 1/12, 2/7, 3/8, 2/9, 3/10, 2/11, and 3/11.
 10. The deviceaccording to claim 7, wherein the value N_(max) is one of: 2048, 1024,and
 512. 11. The device according to claim 7, wherein the constant δ isone of: 1/8, 1/4, and 3/8.
 12. The device according to claim 7, whereinin polar encoding the K data bits, by executing the programinstructions, the processor is configured to: generate a binary rowvector u₁ ^(N1), wherein u₁ ^(N) ¹ =(u₁,u₂, . . . , u_(N) ₁ ), and Kbit-positions of the binary row vector u₁ ^(N) ¹ are occupied by the Kdata bits; and encode the binary row vector u₁ ^(N) ¹ according to anencoding formula, to obtain the encoded bit sequence; wherein theencoding formula is:x₁ ^(N) ¹ =u₁ ^(N) ¹ G_(N1) wherein x₁ ^(N) ¹ =(x₁, x₂, . . . , x_(N) ₁) is the encoded bit sequence, and G_(N) ₁ is a polar code generatingmatrix of N₁ row and N₁ columns.
 13. The device according to claim 7,wherein the device is a base station or a user terminal.
 14. Anon-transitory computer readable medium storing program codes thereonfor execution by a processor in a communication device, wherein theprogram codes comprise instructions for: obtaining K data bits and atarget code length M, wherein K, M are positive integers; determining amother code length N₁ according to a minimum value of values N_(a),N_(max) and N, and N₁ is an integer power of 2; polar encoding the Kdata bits, to obtain a encoded bit sequence, wherein the encoded bitsequence has a code langth of N₁; and outputting, the encoded bitsequence; wherein the values N_(a), N_(max) and N satisfy the followingconditions: the value N_(a) satisfies with: a rate R₁ is less than orequal to a preset rate, wherein the rate R₁ is determined according tothe value K and the value N_(a); the value N_(max) is a preset maximummother code length, wherein N_(max) is an integer power of 2; and thevalue N satisfies with M≤N*(1+δ), wherein δ is a preset constant. 15.The non-transitory computer readable medium according to claim 14,wherein N₁=2^(n), and n is a maximum value of integers less than orequal to log₂ M.
 16. The non-transitory computer readable mediumaccording to claim 14, wherein the preset rate is one of: 1/2, 1/3, 1/4,1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 2/7, 3/8, 2/9, 3/10, 2/11,and 3/11.
 17. The non-transitory computer readable medium according toclaim 14, wherein the value of N_(max) is one of: 2048, 1024, and 512.18. The non-transitory computer readable medium according to claim 14,wherein the constant δ is one of: 1/8, 1/4, and 3/8.
 19. Thenon-transitory computer readable medium according to claim 14, whereinthe instructions for polar encoding the data bits to obtain the encodedsequence comprise: generating a binary row vector u₁ ^(N) ¹ , wherein u₁^(N) ¹ =(u₁, u₂, . . . , u_(N) ₁ ), and K bit-positions of the binaryrow vector u₁ ^(N) ¹ are occupied by the K data bits; and encoding thebinary row vector u₁ ^(N) ¹ according an encoding formula, to obtain theencoded bit sequence; wherein the encoding formula is:x₁ ^(N) ¹ =u₁ ^(N) ¹ G_(N1) wherein x₁ ^(N) ¹ =(x₁, x₂, . . . , x_(N) ₁) is the encoded bit sequence, and G_(N) ₁ is a polar code generatingmatrix of N₁ row and N₁ columns.
 20. The non-transitory computerreadable medium according to claim 14, wherein the communication deviceis a base station or a user terminal.